getUnCheckStudent();
$(".startSearch").click(function() {

	getUnCheckStudent();
})
				
//获取所有未审核的学员开始
function getUnCheckStudent() {
	var name =$(".name").val();// 学生姓名 (String),
	var gender = ''; // 性别 (int),
	var company =$(".company").val();//工作单位 (String),
	var time = $(".createTime").val(); //注册时间
	var englishLevel = $(".englishLevel").val();
	var blood = $(".blood").val();
	var constellation = $(".constellation").val();
	var nation = $(".nation").val();
	var email = $(".email").val();
	var height = $(".height").val();
	var school = $(".school").val();
	var address = $(".address").val();
	var idCard = $(".idCard").val();
	var liaison = $(".liaison").val();
	var available = $('.shenHe option:selected').val();
	var stamp = new Date().getTime(); //数据时间戳
	var version = 0; //数据版本 (int),
	var visit_plat = 0; //访问平台 (int),
	var visit_type = 0; //访问类型 (int),
	var is_used = 0; // 数据是否有效 0有效1失效 (int)
				var systoken = sessionStorage.getItem('systoken');
//	var systoken = 'acc37bf1f8a1486da2664ecfec2902c7';
	layui.use(['table', 'laypage', 'layer','laydate'], function() {
		var laypage = layui.laypage,
			layer = layui.layer;
		var table = layui.table;
		var laydate = layui.laydate;
		//return;
		//渲染
		var stamp = new Date().getTime();
		var systoken = sessionStorage.getItem('systoken');
		// var gender = gender
		var param = {
			available:available,
			blood:blood,
			constellation:constellation,
			nation:nation,
			email:email,
			height:height,
			school:school,
			address:address,
			idCard:idCard,
			liaison:liaison,
			
			englishLevel:englishLevel,
			name: name,
			gender: gender,
			company: company,
			time: time,
			stamp: stamp,

			version: version,
			visit_plat: visit_plat,
			visit_type: visit_type,
			is_used: is_used,
			systoken: systoken
		};
		param = JSON.stringify(param);
		var url = path+"/check/getUnCheckStudent";
		var defaultpageSise = 10;
		window.ins1 = _render(defaultpageSise);
		function _render(pageSize) {
		table.render({
			elem: '#xueSenTest',
			height: 600,
			title: '用户数据表',
			method: 'post',
			url: url,
			page: true,
			where: {
				param: param

			},
            headers:{
                Authorization:systoken
            },
			skin: 'row',
			even: true,
			// autoSort: true,
			loading: false,
			parseData: function(res) {
				var data = res.rows
				for(i = 0; i < data.length; i++) {
					var gender = data[i].gender;
					if(gender == 0) {
						data[i].gender = '男';
					} else {
						data[i].gender = '女';
					};
				}
				return {
					"code": res.status,
					"msg": res.info,
					"count": res.total,
					"data": res.rows
				};
			},
			done: function(res) {
				//手动输入部分
				$('#inp').val(pageSize);
				$("#inp").on('blur', function() {
				      var inputVal = $("#inp").val();
				      _render(inputVal);
				     //getAllTeacher(inputVal);
				});
			},
			totalRow: true,
			limit: 30,
			toolbar: '.toolbarDemo'
				//,defaultToolbar: ['filter']

				,
			cols: [
				[{
						type: 'checkbox',
						fixed: 'left'
					},
					{
						field: 'name',
						title: '姓名',
//						width: 150,
					},
					{
						field: 'account',
						title: '账号',
//						width: 150,
					},
					{
						field: 'gender',
						title: '性别',
//						width: 100,
						templet: "#genderVal"
					},
					
					{
						field: 'age',
						title: '年龄',
//						width: 100
					},
                    {
                        field: 'blood',
                        title: '血型',
//						width: 100
                    },
					{
						field: 'liaison',
						title: '联系方式',
//						width: 200
					},
					{
						field: 'school',
						title: '毕业学校',
//						width: 180
					},
					{
						field: 'email',
						title: '邮箱',
//						width: 200
					},

//					{
//						field: 'rank',
//						title: '职级',
////						width: 120
//					},
					
					{
						field: 'idCard',
						title: '身份证',

					},
					{
						fixed: 'right',
						title: '操作',
						toolbar: '#barDemo',
//						width: 180
					},
				]
			],
			page: true
				,
//			limits: [10, 5, 10],
			limit: pageSize
				,
			loading: true //请求数据时，是否显示loading

		});
	};
	//时间
		laydate.render({
		    elem: '.createTime'
		    ,type: 'datetime'
		});
		// 工具栏事件
		table.on('toolbar(xueSenTest)', function(obj) {
				var checkStatus = table.checkStatus(obj.config.id);
			var exportExel = table.checkStatus('useTest').data;
			switch(obj.event) {
				case 'add':
					layer.msg('添加');
					break;
				case 'update':
					layer.msg('编辑');
					break;
				case 'delete':
					layer.msg('删除');
					break;
				case 'getCheckData':
					var studentsId = checkStatus.data;
					exportExel=checkStatus.data;
					passChecked(studentsId);
					break;
				case 'getChecktedData':
					var studentsId = checkStatus.data;
					exportExel=checkStatus.data;
					upPassChecked(studentsId);
					break;						
				case 'getCheckLength':
					var data = checkStatus.data;
					layer.msg('选中了：' + data.length + ' 个');
					break;
				case 'isAll':
					layer.msg(checkStatus.isAll ? '全选' : '未全选')
					break;
			};
		});
		//封装多选删通过函数开始1203修改
			function passChecked(studentsId,index){
//				var studentsId = studentsId.id;
				var paramCheck={studentsId:studentsId};
				var idArr=[];
//				var forPass=0;
				var studentsData=paramCheck.studentsId;
				if(!studentsData.length){
					alert("请先选择需要通过的学员！");
					return;
				}
				for(var i=0;i<studentsData.length;i++){
					idArr.push({studentId:studentsData[i].id});
				}
				var param1={studentsId:idArr};
//				var param2={"tableName":""};
				var param3={forPass:1}; 
				var systoken = sessionStorage.getItem('systoken');
				var param=Object.assign(param1,publicParam,param3,{systoken:systoken});
				param=JSON.stringify(param);
				var url = path+"/check/checkStudent";
				$.ajax({
					url: url,
//				url: path+"/studentClass/deleteStudentClass",
					type: "post",
					data: {
						param: param
					},
                    headers:{
                        Authorization:systoken
                    },
					dataType: "json",
					success: function() {
						//						重新查询数据
						alert("通过成功!")
						getUnCheckStudent();
					}
				})
			}
				//封装多选不通过函数开始1203修改
			function upPassChecked(studentsId,index){
//				var studentsId = studentsId.id;
				var paramCheck={studentsId:studentsId};
				var idArr=[];
//				var forPass=0;
				var studentsData=paramCheck.studentsId;
				if(!studentsData.length){
					alert("请先选择不通过的学员！");
					return;
				}
				for(var i=0;i<studentsData.length;i++){
					idArr.push({studentId:studentsData[i].id});
				}
				var param1={studentsId:idArr};
//				var param2={"tableName":""};
				var param3={forPass:2}; 
				var systoken = sessionStorage.getItem('systoken');
				var param=Object.assign(param1,publicParam,param3,{systoken:systoken});
				param=JSON.stringify(param);
				var url = path+"/check/checkStudent";
				$.ajax({
					url: url,
//				url: path+"/studentClass/deleteStudentClass",
					type: "post",
					data: {
						param: param
					},
                    headers:{
                        Authorization:systoken
                    },
					dataType: "json",
					success: function() {
						//						重新查询数据
						alert("不通过成功!")
						
						getUnCheckStudent();

					}

				})
				

			}
		
		//监听表格行点击
		table.on('tr', function(obj) {
		});

		//监听表格复选框选择
		table.on('checkbox(xueSenTest)', function(obj) {
		});

		//监听表格单选框选择
		table.on('radio(xueSenTest)', function(obj) {
		});
		//监听表格单选框选择
		table.on('rowDouble(xueSenTest)', function(obj) {
		});

		//监听单元格编辑
		table.on('edit(xueSenTest)', function(obj) {

			var value = obj.value //得到修改后的值
				,
				xgdata = obj.data //得到所在行所有键值
				,
				id = xgdata.id //得到id
				,
				field = obj.field; //得到字段
			//						双击单元格改变一个值就可以在这里取得,在这里进行与后台交互,修改信息,

			//编辑单元格
			editTeacher();
			$('.teachername').val("");
			//修改成功与后台交互
			function editTeacher() {

				var stamp = new Date().getTime();
				var version = 0;
				var visit_plat = 0;
				var visit_type = 0;
				var is_used = 0;
				var systoken = sessionStorage.getItem('systoken');
				var param1 = {
					//										obj[field]:value,
					id: id,
					stamp: stamp,
					systoken: systoken,
					version: version,
					visit_plat: visit_plat,
					visit_type: visit_type,
					is_used: is_used
				}
				var param = Object.assign(xgdata, param1);
				param = JSON.stringify(param);
				var url = path+"/teacher/updateTeacher";
				$.ajax({
					url: url,
					type: "post",
					data: {
						param: param
					},
					dataType: "json",
					success: function() {
						getAllTeacher();
					}
				})
			}
		});

		//监听行工具事件
		table.on('tool(xueSenTest)', function(obj) {
			var data = obj.data;
			//						var id = data.id;
			if(obj.event === 'del') {
				layer.confirm('确定删除这一行数据?', function(index) {
					//							这里编写删除的逻辑,下面两个步骤是完成与后台的交互后才执行的
					var id = data.id;
					obj.del();
					layer.close(index);
					//								删除表格
					deleteTeacher();

					function deleteTeacher() {
						var systoken = sessionStorage.getItem('systoken');
						var stamp = new Date().getTime();
						var version = 0;
						var visit_plat = 0;
						var visit_type = 0;
						var is_used = 0;
						var param = {
							id: id,
							systoken: systoken,
							stamp: stamp,
							version: version,
							visit_plat: visit_plat,
							visit_type: visit_type,
							is_used: is_used
						}
						param = JSON.stringify(param);
						var url = path+"/teacher/deleteTeacher";
						$.ajax({
							url: url,
							type: "post",
							data: {
								param: param
							},
							dataType: "json",
							success: function() {
								getAllTeacher();
							}
						})
					}
				});
			} else if(obj.event === 'edit') {
				layer.prompt({
					formType: 2,
					value: data.liaison
					//							value: data.experience
				}, function(value, index) {
					obj.update({
						email: value
					});
					layer.close(index);
				});
			}else if(obj.event==='pass'){
				
				layer.confirm('确定通过此学员吗?', function(index) {
					//							这里编写删除的逻辑,下面两个步骤是完成与后台的交互后才执行的
						var id = data.id;
					var studentsId=[{studentId:id}];

					layer.close(index);
					checkStudent();

					function checkStudent() {
						var systoken = sessionStorage.getItem('systoken');
						var stamp = new Date().getTime();
						var version = 0;
						var visit_plat = 0;
						var visit_type = 0;
						var is_used = 0;
						var forPass=1;

						var param = {
							studentsId: studentsId,
							forPass:forPass,
							systoken: systoken,
							stamp: stamp,
							version: version,
							visit_plat: visit_plat,
							visit_type: visit_type,
							is_used: is_used
						}
						param = JSON.stringify(param);
						var url = path+"/check/checkStudent";
						$.ajax({
							url: url,
							type: "post",
							data: {
								param: param
							},
                            headers:{
                                Authorization:systoken
                            },
							dataType: "json",
							success: function() {
								getUnCheckStudent();
							}
						})
					}
				});
			}else if(obj.event==='unPass'){
				layer.confirm('确定不通过此学员吗?', function(index) {
					//							这里编写删除的逻辑,下面两个步骤是完成与后台的交互后才执行的
					var id = data.id;
					var studentsId=[{studentId:id}];
					layer.close(index);
					checkStudent();

					function checkStudent() {
						var systoken = sessionStorage.getItem('systoken');
						var stamp = new Date().getTime();
						var version = 0;
						var visit_plat = 0;
						var visit_type = 0;
						var is_used = 0;
						var forPass=2;

						var param = {
							studentsId: studentsId,
							forPass:forPass,
							systoken: systoken,
							stamp: stamp,
							version: version,
							visit_plat: visit_plat,
							visit_type: visit_type,
							is_used: is_used
						}
						param = JSON.stringify(param);
						var url = path+"/check/checkStudent";
						$.ajax({
							url: url,
							type: "post",
							data: {
								param: param
							},
                            headers:{
                                Authorization:systoken
                            },
							dataType: "json",
							success: function() {
								getUnCheckStudent();
							}
						})
					}
				});
			}
		});

		//监听排序
		table.on('sort(xueSenTest)', function(obj) {
			layer.msg('已经完成排序！ ' + obj.field + ' ' + obj.type);
			//服务端排序
			table.reload('xueSenTest', {
				initSort: obj
					//,page: {curr: 1}
					,
				where: {
					key: obj.field
						,
					order: obj.type
				}
			});
		});

		var $ = layui.jquery,
			active = {
				parseTable: function() {
					table.init('parse-table-demo', {
						limit: 3
					});
				},
				add: function() {
					table.addRow('xueSenTest')
				}
			};
		$('i').on('click', function() {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});
		$('.layui-btn').on('click', function() {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		})
	});
}

//删除用户开始
function deleteTeacher() {
	var systoken = sessionStorage.getItem('systoken');
	var stamp = new Date().getTime();
	var version = 0;
	var visit_plat = 0;
	var visit_type = 0;
	var is_used = 0;
	var param = {
		id: id,
		stamp: stamp,
		systoken: systoken,
		version: version,
		visit_plat: visit_plat,
		visit_type: visit_type,
		is_used: is_used
	}
	param = JSON.stringify(param);
	$.ajax({
		url: "",
		type: "post",
		data: {
			param: param
		},
		dataType: "json",
		success: function() {
			//重新查询数据
			getAllTeacher();
		}

	})
}

//通过学员
$("#pass").click(function(){
	alert("1");
})
